# Copyright (C) 2022-2024 Inspur Corp. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

# 数字身份安装目录
DIR=$1
# nginx配置ip，当前服务器ip
DID_IP='192.168.56.1'
# nginx配置端口，默认为80，若有端口冲突则修改
DID_PORT='80'
# nginx访问host
DID_HOST="${DID_IP}:${DID_PORT}"

 
if [ ! -n "$DIR" ]; then
	DIR=/data/did
fi

if [ ! -d "$DIR" ]; then
	echo "create install dir..."
	mkdir -p $DIR
fi

load_image() {
	cd images/
	sh load.sh
	cd ../
}

setup() {
	echo "copy config and docker-compose.yaml to install dir ..."
	cp -r ./config $DIR/
	cp ./docker-compose.yaml $DIR/

	echo "modify parameters of docker-compose.yaml"
	eval sed -i 's#{did-dir}#${DIR}#g' $DIR/docker-compose.yaml
	eval sed -i 's#{did-host}#${DID_HOST}#g' $DIR/docker-compose.yaml
	eval sed -i 's#{did-port}#${DID_PORT}#g' $DIR/docker-compose.yaml

	echo "create runtime dir ..."
	mkdir -p $DIR/runtime/did-db
	mkdir -p $DIR/runtime/did-redis/data
	mkdir -p $DIR/runtime/www
	
	echo "create docker network ibc ..."
	docker network create ibc
}

load_image

setup
